<?php namespace App\Controllers\Manager;
 
use App\Models\Video;
use Input, Redirect, Sentry, Str, Response, Config;
use Notification;
 
class VideosController extends \BaseController {
 
    public function index()
    {
        return \View::make('manager.videos.index')
            ->with('videos', Video::all());
    }
 
    public function show($id)
    {
        /*return \View::make('manager.pages.show')
            ->with('page', Page::find($id));*/
    }
 
    public function create()
    {
        return \View::make('manager.videos.create');
    }
 
    public function store()
    {
        $video = new Video;
        $video->title   = Input::get('title');
        $video->slug    = Str::slug(Input::get('slug'));
        $video->youtube_link   = Input::get('youtube_link');
        $video->save();
        
        Notification::success('The video was saved.');
     
        return Redirect::route('manager.videos.index');
    }
 
    public function edit($id)
    {
        $video = Video::find($id);
		
		return \View::make('manager.videos.edit')
            ->with('video', $video);
    }
 
    public function update($id)
    {
        $video = Video::find($id);
        $video->title   = Input::get('title');
        $video->slug    = Str::slug(Input::get('slug'));
        $video->youtube_link   = Input::get('youtube_link');
        
		$video->save();
		
		Notification::success('The video was saved.');
     
        return Redirect::route('manager.videos.edit', $video->id);
    }
 
    public function destroy($id)
    {
        $video = Video::find($id);
        $video->delete();

        Notification::info('The video was deleted.');

        return Redirect::route('manager.videos.index');
    }

    public function getSlug()
    {
        return Response::json(array(
            "val" => Str::slug(Input::get("str"))
        ));
    }
}